package com.smartcruise.util;

import android.text.TextUtils;
import android.widget.TextView;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by FengChaoQun
 * on 2017/1/16
 */

public class StringUtils {

    public static boolean isNotEmpty(TextView... textViews) {
        for (TextView textView : textViews) {
            if (TextUtils.isEmpty(textView.getText().toString())) {
                return false;
            }
        }
        return true;
    }

    public static boolean isEmail(String email) {
        Pattern p = Pattern.compile("[\\w\\.\\-]+@([\\w\\-]+\\.)+[\\w\\-]+", Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(email);
        return m.matches();
    }

    public static boolean isNotNullAndNotNullString(String string) {
        return !(TextUtils.isEmpty(string) || string.equals("null"));
    }

    public static String join(List<String> strings, String delimiter) {
        if (strings == null || strings.isEmpty() || delimiter == null) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < strings.size(); i++) {
            sb.append(strings.get(i));
            if (i != strings.size() - 1) {
                sb.append(Key.SPLIT);
            }
        }
        return sb.toString();
    }

}
